home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 266_01 / monitor.c < prev    next >
C/C++ Source or Header  |  1990-04-25  |  5KB  |  165 lines

  1. /*
  2.       Common code for all IBM-compatible graphics monitor drivers.
  3.       Copyright 16 April 1990, Robert L. Patton, Jr.
  4. */
  5. #define GETINT GetWord
  6. #define  GETXY(A,B) A=DX(GETINT(Plot))+Xo;B=DY(GETINT(Plot))+Yo;
  7.  
  8. void Line (int X1,int Y1,int X2,int Y2)
  9. /*   ====               Draws a straight line */
  10. {
  11.   int Dx, Dy, D1x, D1y, D2x, D2y, M, N, S, K;
  12.  
  13.   Dx = X2 - X1;
  14.   Dy = Y2 - Y1;
  15.   D1x = Sign(Dx);
  16.   D1y = Sign(Dy);
  17.   D2x = D1x;
  18.   D2y = 0;
  19.   M = abs(Dx);
  20.   N = abs(Dy);
  21.   if (M <= N) {
  22.     D2x = 0;
  23.     D2y = D1y;
  24.     M = abs(Dy);
  25.     N = abs(Dx);
  26.   }
  27.   S = M/2;
  28.   for (K=0; K<=M; K++)
  29.   {
  30.     if (Dotter())  DOT (X1,Y1);
  31.     S += N;
  32.     if (S >= M) {
  33.       S -= M;
  34.       X1 += D1x;
  35.       Y1 += D1y;
  36.     }
  37.     else {
  38.       X1 += D2x;
  39.       Y1 += D2y;
  40.     }
  41.   }
  42. }
  43. /* ----------------------------------------------------*/
  44. main(int ArgC,char **ArgV)
  45. {
  46.   FILE *Plot;
  47.   #include "bitfont.h"
  48.   static int  Command=0,Xp=0,Yp=0,Xo=0,Yo=0;
  49.   int  I,J,M,N,X,Y,X2,Y2,Shape,Pattern,Density,Hit,Gap,Color;
  50.   unsigned Count=0;
  51.  
  52.   if((Plot=fopen("PLOTCOM.DAT","rb"))==NULL) {
  53.       puts("Plot file, PLOTCOM.DAT not found. No picture possible.\n");
  54.       puts("Do a PLOX command on a .PIC file before trying to plot.\n");
  55.       exit(0);
  56.   }
  57.   TVON;
  58.   if (ArgC>1) NEWHUE(atoi(ArgV[1]));
  59.   else        NEWHUE(NORMAL);
  60.   SetLine (SOLID);
  61.   while (Command<99)  {
  62.     Command=getc(Plot);
  63.     if(Command==EOF) Command=99;
  64.     switch (Command)
  65.     {
  66.       case   ON: GETXY(Xp,Yp)    /* Set pixel */
  67.                  DOT(Xp,Yp);
  68.                  break;
  69.  
  70.       case MARK: GETXY(X,Y)       /* Move and mark */
  71.                  Line(Xp,Yp,X,Y);
  72.                  Xp=X;Yp=Y;
  73.                  break;
  74.  
  75.       case MOVE: GETXY(Xp,Yp)    /* Move */
  76.                  break;
  77.  
  78.       case LTYP: SetLine (getc(Plot)); /* Set line type */
  79.                  break;
  80.  /* */
  81.       case TXTH: ;                /* Font 1 horizontal */
  82.       case TXTV: GETXY(X,Y)       /* Font 1 vertical */
  83.                  while ((N=getc(Plot))!=0) {
  84.                   if(N<0x20) N=0x20;
  85.                   else if(N>0x5F) N-=0x20;
  86.                   N=Font1[N-0x20];
  87.                   for(J=0;J<5;J++)
  88.                     for(I=0;I<3;I++) {
  89.                       if(N&1) DOT(X+I,Y-J);
  90.                         N=N>>1;
  91.                     }
  92.                   if (Command==TXTH) X+=5;
  93.                   else               Y-=7;
  94.                  }
  95.                  Xp=X;Yp=Y;
  96.                  break;
  97.       case TX2H:                  /* Font 2 horizontal */
  98.       case TX2V: GETXY(X,Y)       /* Font 2 vertical */
  99.                  while ((N=getc(Plot))!=0) {
  100.                   if(N<0x20) N=0x20;
  101.                   N-=0x20;
  102.                   M=Font2[N][0];
  103.                   N=Font2[N][1];
  104.                   for (I=0;I<5;I++)
  105.                     for (J=0;J<3;J++) {
  106.                       if (M&1) DOT(X+I,Y-J);
  107.                       if (N&1) DOT(X+I,Y-J-3);
  108.                       M=M>>1;
  109.                       N=N>>1;
  110.                     }
  111.                     if (Command==TX2H) X+=7;
  112.                     else               Y-=8;
  113.                   }
  114.                   Xp=X; Yp=Y;
  115.                   break;
  116.  
  117.       case SYMB: Shape=getc(Plot); /* Draw symmetrical symbol */
  118.                  for(J=1;J<3;J++)
  119.                    for(I=2;I>=0;I--) {
  120.                      if(Shape&1) {
  121.                        DOT(Xp+I,Yp+J);
  122.                        DOT(Xp-J,Yp+I);
  123.                        DOT(Xp-I,Yp-J);
  124.                        DOT(Xp+J,Yp-I);
  125.                      }
  126.                      Shape=Shape>>1;
  127.                    }
  128.                  if(Shape%2) DOT(Xp,Yp);
  129.                  break;
  130.  
  131.       case ORIG: Xo=DX(GETINT(Plot)); /* New origin */
  132.                  Yo=DY(GETINT(Plot));
  133.                  break;
  134.  
  135.       case MRGN: GETINT(Plot);  /* No margin with crt graph */
  136.                  break;
  137.  
  138.       case HTYP: Pattern=GETINT(Plot);  /* Set hatch type */
  139.                  Density=GETINT(Plot);
  140.                  SetHatch (Pattern,Density);
  141.                  break;
  142.  
  143.       case FILL: GETXY(X,Y)    /* Hatch area */
  144.                  GETXY(X2,Y2)
  145.                  for (J=Y+1;J<Y2;J++) {
  146.                    HatchHow (J-Y,&Hit,&Gap);
  147.                    for (I=X+1;I<X2;I++)
  148.                      if ((I-X+Hit)%Gap) NODOT(I,J)
  149.                      else                 DOT(I,J);
  150.                  }
  151.                  break;
  152.  
  153.       case  HUE: Color = GETINT(Plot);
  154.                  NEWHUE(Color);
  155.                  break;
  156.  
  157.       case CLOS: fclose(Plot);
  158.                  Xp=Yp=Xo=Yo=0;
  159.                  break;
  160.     }
  161.   }
  162.   getch();
  163.   TVOFF;
  164. }
  165.